package com.yangli.leecode.mashib.interview;

import java.util.Arrays;

/**
 * @Description
 * @Author liyang
 * @Date 2023/3/6 15:48
 */
public class FortyThree {
    public static void main(String[] args){

        int[][] arr = new int[][]{{1, 1, 2, 0}, {5, 0, 1, 1}, {5, 5, 5, 7,}};
        FortyThree.setZones(arr);

    }


    //073
    public static void setZones(int[][] arr){
        System.out.println(Arrays.toString(arr[0]));
        System.out.println(Arrays.toString(arr[1]));
        System.out.println(Arrays.toString(arr[2]));


        //实际代码开始
        boolean zeroClo = false;
        int i = 0;//循环中不再定义变量
        int j = 0;
        for (i = 0; i < arr.length; ++i) {
            for (j = 0; j < arr[0].length; ++j) {
                if (arr[i][j] == 0) {
                    arr[i][0] = 0;
                    if (j == 0) {
                        zeroClo = true;
                    } else {
                        arr[0][j] = 0;
                    }

                }

            }
        }
        for (i = arr.length - 1; i >= 0; --i) {
            for (j = 1; j < arr[0].length; ++j) {
                if (arr[i][0] == 0 || arr[0][j] == 0) {
                    arr[i][j] = 0;
                }
            }
        }

        if (zeroClo) {
            for (i = 0; i < arr.length; i++) {
                arr[i][0] = 0;
            }
        }
        System.out.println(Arrays.toString(arr[0]));
        System.out.println(Arrays.toString(arr[1]));
        System.out.println(Arrays.toString(arr[2]));


    }


}
